package edu.etu.sob.service;

import java.io.IOException;
import java.io.InputStream;

import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.util.FileManager;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;

public class OntologyManager implements IOntologyManager {

	public OntModel createOntologyModel(String url) throws IOException {
		
		OntologyProvider modelCache = OntologyProvider.getInstance();
		if (modelCache.isModelAvailable(url)) {
			return modelCache.getModel(url);
		}
		
		//TODO logging
		System.out.println("Creating ontology model... Please wait...\n");
		
		OntModel _model = ModelFactory.createOntologyModel();
		InputStream instr = FileManager.get().open(url);
		_model.read(instr, null);
		instr.close();
		
		return _model;
	}
	
	public ExtendedIterator listClasses(final OntModel model) {
		return model.listClasses();
	}
}
